package com.youi.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.dao.DistrictcodeDao;
import com.youi.entity.Citycode;
import com.youi.entity.Districtcode;
import com.youi.service.CitycodeService;
import com.youi.service.DistrictcodeService;

@Service
public class DistrictcodeServiceImpl extends BaseServiceImpl<Districtcode> implements DistrictcodeService{
		
		private DistrictcodeDao districtcodeDao;
		
		@Autowired
		private CitycodeService citycodeService;
		@Autowired
		public void setfaultRecordDao(DistrictcodeDao districtcodeDao){
			this.districtcodeDao=districtcodeDao;
			super.setBaseDAO(districtcodeDao);
		}

		@Override
		public String getDistrictcodeByDistrict(String district) {
			// TODO Auto-generated method stub
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("name", district);
			Districtcode districtcode=districtcodeDao.getObject(prams);
			if (districtcode!=null) {
				return districtcode.getCode();
			}
			return null;
		}

		@Override
		public String getDistrictcodeByCity(String city) {
			// TODO Auto-generated method stub
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("name", city);
			Citycode citycode=citycodeService.getByParam(prams);
			if (citycode!=null) {
				prams=new HashMap<String, Object>();
				prams.put(Common.DELSTATUS, DelStatus.NODEL);
				prams.put("cityId", citycode.getId());
				Districtcode districtcode=districtcodeDao.getObject(prams);
				if (districtcode!=null) {
					return districtcode.getCode();
				}
			}
			return null;
		}
}